using System;
using System.Collections.Generic;
using System.Text;
using Ltf.Remoting.Settings;
using System.Xml.Serialization;

namespace Lizard.Remoting.Settings
{
	[Serializable]
	public class TFSecondarySettings : TFSettings
	{
		public TFSecondarySettings()
		{
		}

		private TFSettings primarySettings;
		
		public TFSecondarySettings(TFSettings primarySettings)
		{
			this.primarySettings = primarySettings;
		}

		[XmlIgnore]
		public TFSettings PrimarySettings
		{
			get { return primarySettings; }
			set { primarySettings = value; }
		}

		[XmlIgnore]
		public override string EditTool
		{
			get
			{
				return primarySettings.EditTool;
			}
			set
			{
				return;
				// throw new NotImplementedException("The Edit Tool can only be set for the default server");
			}
		}

		[XmlIgnore]
		public override string Excludedfiles
		{
			get
			{
				return primarySettings.Excludedfiles;
			}
			set
			{
				return;
				// throw new NotImplementedException("Excluded files can only be set for the default server");
			}
		}

		[XmlIgnore]
		public override string Excludedfolders
		{
			get
			{
				return primarySettings.Excludedfolders;
			}
			set
			{
				return;
				// throw new NotImplementedException("Excluded folders can only be set for the default server");
			}
		}

		[XmlIgnore]
		public override string IncludedDrives
		{
			get
			{
				return primarySettings.IncludedDrives;
			}
			set
			{
				return;
				// throw new NotImplementedException("Included drives can only be set for the default server");
			}
		}

		[XmlIgnore]
		public override string LtfMetaFolderName
		{
			get
			{
				return primarySettings.LtfMetaFolderName;
			}
			set
			{
				return;
				// throw new NotImplementedException("Lizard meta folder path can only be set for the default server");
			}
		}

		[XmlIgnore]
		public override string TempPath
		{
			get
			{
				return primarySettings.TempPath;
			}
			set
			{
				return;
				// throw new NotImplementedException("Lizard temp. folder path can only be set for the default server");
			}
		}

		[XmlIgnore]
		public override string X64InstallPath
		{
			get
			{
				return primarySettings.X64InstallPath;
			}
			set
			{
				return;
				// throw new NotImplementedException("x64 install folder path can only be set for the default server");
			}
		}

		private List<string> serverPaths;

		public string ServerPaths
		{
			get
			{
				return string.Join("; ", serverPaths.ToArray());
			}
			set
			{
				serverPaths = new List<string>(value.Split(';'));
			}
		}

		public bool AppliesToPath(string path)
		{
			// if these settings are forced, then return true
			if (!string.IsNullOrWhiteSpace(primarySettings.ForcedServer) && primarySettings.ForcedServer == this.Server)
				return true;

			// otherwise check to see if this settings paths apply.
			foreach (string p in serverPaths)
			{
				if (path.StartsWith(p))
					return true;
			}
			return false;
		}

		[XmlIgnore]
		public override sealed List<TFSecondarySettings> AlternativeServerSettings
		{
			get
			{
				return null;
			}
			set
			{
				return;
			}
		}

		public override bool IsFilePathIncluded(string path)
		{
			return primarySettings.IsFilePathIncluded(path);
		}

		public override bool IsFolderPathIncluded(string path)
		{
			return primarySettings.IsFolderPathIncluded(path);
		}

		public override bool IsFullFilePathIncluded(string path)
		{
			return primarySettings.IsFullFilePathIncluded(path);
		}
	}
}
